//
//  StackPage.swift
//  PracticeDemo
//
//  Created by 顾浩然 on 2025/1/26.
//

import SwiftUI

struct StackPage: View {
    //这么声明类似Android上的RequiresApi
    #if !os(macOS)
    @Environment(\.horizontalSizeClass) var horizontalSizeClass
    #endif
    
    var body: some View {
        VStack{
            //参数1对齐方式 参数2各元素间距
            HStack(alignment: .top,spacing: 10){
                Text("SwitchUI")
                //占位组件
                Spacer()
                Text("rocks")
            }
            .frame(height: 50)
            .padding(.horizontal)
            
            ZStack{
                Rectangle()
                    .fill(Color.red)
                    .frame(width: 70, height: 70)
                    //zIndex默认0 越大层级越高
                    .zIndex(1)
                Rectangle()
                    .fill(Color.blue)
                    .frame(width: 50, height: 50)
                    .zIndex(2)
            }
            //通过这个方法可以判断横竖屏幕
            if(horizontalSizeClass == .compact){
                Text("is compact")
            }else{
                Text("is regular")
            }
        }
    }
}

struct StackPage_Previews: PreviewProvider {
    static var previews: some View {
        StackPage()
    }
}
